<?php

/**
 * @name NociceController
 * @desc 控制器
 */
class NoticeController extends UserCommonController
{
    //公告列表
    public function listAction(){

        $params = $this->post();

        $row = $params['pageSize'] ?? 12;
        $page = $params['page'] ?? 1;

        $noticeModel = NoticeModel::getSingleton();
        $list = $noticeModel->db
            ->where(['is_show'=> 1])
            ->order('id desc')
            ->limit(($page - 1) * $row, $row)
            ->select();
        $total = $noticeModel->db
            ->where(['is_show'=> 1])
            ->count();

        $data = [
            'list' => $list,
            'total' => intval($total),
            'current'   => intval($page),
            'pageSize'  => intval($row),
            'page'  => intval($page),
            'pageNum'   => ceil($total/$row)
        ];

        $this->ajaxReturn(0, '', $data);
    }

    //详情
    public function detailAction(){
        $params = $this->post();

        if(!isset($params['id'])){
            $this->ajaxReturn(400, '未获取到数据ID');
        }

        $noticeModel = NoticeModel::getSingleton();
        $detail = $noticeModel->find(['id'=> $params['id']]);

        if(!$detail){
            $this->ajaxReturn(400, '数据ID错误');
        }

        $this->ajaxReturn(0, 'success', $detail);
    }

}
